package com.huawei.petapp2.activity;

import android.view.View;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;

import com.huawei.petapp2.R;
import com.huawei.petapp2.activity.widget.BaseActivity;
import com.huawei.petapp2.activity.widget.NoScrollViewPager;
import com.huawei.petapp2.adapter.ViewPagerAdapter;
import com.huawei.petapp2.cart.CartFragment;
import com.huawei.petapp2.category.CategoryFragment;
import com.huawei.petapp2.community.CommunityFragment;
import com.huawei.petapp2.fragment.HomeFragment;
import com.huawei.petapp2.network.core.ResponseEntity;
import com.jaeger.library.StatusBarUtil;

import java.util.ArrayList;

public class StoreActivity extends BaseActivity implements View.OnClickListener{

    private LinearLayout mLlHome;
    private LinearLayout mLlClassify;
    private LinearLayout mdongtai;
    private LinearLayout mL1Service;
    private NoScrollViewPager mViewPager;

    private View v;




    @Override
    protected int setLayoutId() {
        return R.layout.activity_store;
    }

    @Override
    public void initView() throws Exception {
        v=getWindow().getDecorView();
        mViewPager = findViewById(R.id.app_act_store_vp);
        mLlHome = findViewById(R.id.app_include_bottom_store_ll_home);
        mLlClassify = findViewById(R.id.app_include_bottom_store_ll_cart);
        mdongtai=findViewById(R.id.app_include_bottom_store_ll_trends);
        mL1Service=findViewById(R.id.app_include_bottom_store_ll_service);

    }

    @Override
    public void initData() throws Exception {
        //添加Fragment
        ArrayList<Fragment> mFragments = new ArrayList<androidx.fragment.app.Fragment>();
        mFragments.add(new HomeFragment());
        mFragments.add(new CategoryFragment());
        mFragments.add(new CommunityFragment());
        mFragments.add(new CartFragment());

        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), mFragments);
        mViewPager.setAdapter(adapter);
        mViewPager.setScroll(false);
        mLlHome.setSelected(true);

    }

    @Override
    public void initEvent() {
        mLlHome.setOnClickListener(this);
        mLlClassify.setOnClickListener(this);
        mdongtai.setOnClickListener(this);
        mL1Service.setOnClickListener(this);
    }

    @Override
    protected void onBusinessResponse(String apiPath, boolean success, ResponseEntity rsp) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //首页
            case R.id.app_include_bottom_store_ll_home:
                StatusBarUtil.setTranslucentForImageViewInFragment(this, 0, null);
                StatusBarUtil.setLightMode(this);
                mViewPager.setCurrentItem(0);
                tabSelected(mLlHome);
                break;
            //分类
            case R.id.app_include_bottom_store_ll_cart:
                StatusBarUtil.setLightMode(this);
                StatusBarUtil.setColor(this, getResources().getColor(R.color.white), 0);
                mViewPager.setCurrentItem(1);
                tabSelected(mLlClassify);
                break;
            //店铺
            case R.id.app_include_bottom_store_ll_trends:
                StatusBarUtil.setLightMode(this);
                StatusBarUtil.setColor(this, getResources().getColor(R.color.white), 0);
                mViewPager.setCurrentItem(2);
                tabSelected(mdongtai);
                break;
            //客服
            case R.id.app_include_bottom_store_ll_service:
                StatusBarUtil.setLightMode(this);
                StatusBarUtil.setColor(this, getResources().getColor(R.color.white), 0);
                mViewPager.setCurrentItem(3);
                tabSelected(mL1Service);
                break;
            default:
                StatusBarUtil.setTranslucentForImageViewInFragment(this, 0, null);
                mViewPager.setCurrentItem(0);
                tabSelected(mLlHome);
                break;
        }
    }

    /**
     * Tab选中
     *
     * @param linearLayout
     */
    private void tabSelected(LinearLayout linearLayout) {
        mLlHome.setSelected(false);
        mLlClassify.setSelected(false);
        mdongtai.setSelected(false);
        mL1Service.setSelected(false);
        linearLayout.setSelected(true);
    }

    @Override
    protected void setStatusBar() {
        super.setStatusBar();
        StatusBarUtil.setTranslucentForImageViewInFragment(this, 0, null);
        StatusBarUtil.setLightMode(this);
    }


}